package com.sumainfor.pc.epc.controller.master;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.epc.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 */
@RestController
@RequestMapping("/master/commodity")
public class CommodityController implements Serializable{

    @Autowired
    private CommodityService commodityService;
    /**
     * 根据商品类型查询商品的名称和编号
     * @param params
     * @return
     */
    @RequestMapping(value = "/getCommodityByComType",method = RequestMethod.GET)
    public JsonResult getCommodityByComType(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=commodityService.getCommodityByComType(params);
        System.out.print("List:"+list);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }

        return result;
    }
    /**
     * 根据商品名称查询商品对应的规格名称和编号
     * @param params
     * @return
     */
    @RequestMapping(value = "/getCommoditySpeByComName",method = RequestMethod.GET)
    public JsonResult getCommoditySpeByComName(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=commodityService.getCommoditySpeByComName(params);
        System.out.print("List:"+list);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     * 根据规格名称查询对应的型号和单位
     * @param params
     * @return
     */
    @PostMapping
    @GetMapping
    @RequestMapping(value = "/getCommoditySpeMoByComSpeName",method = RequestMethod.GET)
    public JsonResult getCommoditySpeMoByComSpeName(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=commodityService.getCommoditySpeMoByComSpeName(params);
        System.out.print("List:"+list);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
}
